package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.page.PageBeen;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.service.GoodsService;
import com.dongdongshop.service.TbItemCatSerive;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.zip.DataFormatException;

@Controller
@RequestMapping("tbGoods")
public class TbGoodsController {
    @Reference
    private GoodsService goodsService;
    @Reference
    private TbItemCatSerive tbItemCatSerive;

    @RequestMapping("goods")
    public String goods() {
        return "admin/goods";
    }

    @RequestMapping("showItem")
    @ResponseBody
    public Result showItem() {

        List<TbItemCat> list = tbItemCatSerive.showItem();
        return Result.response(ResultEnum.SUCCESS).setData(list);
    }

    @RequestMapping("getGood")
    @ResponseBody
    public Result getGood(String goodsName, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "4") Integer pageSize) {
        PageBeen<TbGoods> pageBeen = goodsService.selectGoods(goodsName, pageNum, pageSize);
        return Result.response(ResultEnum.SUCCESS).setData(pageBeen);
    }
    @RequestMapping("deleteInfo")
    @ResponseBody
    public Result deleteInfo(Long[] ids) {
        String isDelete = "0";
       int i = goodsService.deleteInfoDelete(isDelete,ids);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("pass")
    @ResponseBody
    public Result pass(Long[] ids){
//     未审核0
//    审核通过1
//    审核未通过2
        String auditStatus = "1";
        int i = goodsService.update(auditStatus, ids);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("noPass")
    @ResponseBody
    public Result Nopass(Long[] ids){
//     未审核0
//    审核通过1
//    审核未通过2
        String auditStatus = "2";
        int i = goodsService.update(auditStatus, ids);
        return Result.response(ResultEnum.SUCCESS);
    }

}
